#! python
#! coding: utf-8

__author__ = 'Anton Vakhrushev'

import wx


class SyncSettingsDialog(wx.Dialog):
    def __init__(self, alb, parent=None):
        wx.Dialog.__init__(self, parent, title=u'Настройки альбома')

        self.album = alb
        """@type : PhotoAlbum"""

        self.sync_checkbox = wx.CheckBox(self, wx.NewId(), u'Включить синхронизацию')
        self.sync_checkbox.SetValue(bool(self.album.sync))
        self.folder_input = wx.TextCtrl(self, wx.NewId(), unicode(self.album.folder or ''))
        self.folder_btn = wx.Button(self, wx.NewId(), u'...', size=(25, -1))
        self.pattern_input = wx.TextCtrl(self, wx.NewId(), unicode(self.album.pattern or ''))
        self.deep_input = wx.TextCtrl(self, wx.NewId(), unicode(self.album.deep or 1))

        folder_sizer = wx.BoxSizer()
        folder_sizer.Add(self.folder_input, 1, wx.EXPAND | wx.ALL)
        folder_sizer.Add(self.folder_btn, 0, wx.LEFT, 5)

        input_sizer = wx.FlexGridSizer(4, 2, 5, 10)
        input_sizer.AddGrowableCol(1)
        input_sizer.Add(wx.StaticText(self, wx.NewId(), u'Директория'))
        input_sizer.AddSizer(folder_sizer, 1, wx.EXPAND | wx.ALL)
        input_sizer.Add(wx.StaticText(self, wx.NewId(), u'Шаблон'))
        input_sizer.Add(self.pattern_input, 1, wx.EXPAND | wx.ALL)
        input_sizer.Add(wx.StaticText(self, wx.NewId(), u'Глубина синхронизации'))
        input_sizer.Add(self.deep_input, 1, wx.EXPAND | wx.ALL)
        input_sizer.AddStretchSpacer()
        input_sizer.Add(self.sync_checkbox, 1, wx.EXPAND | wx.ALL)

        btn_sizer = self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL)

        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.AddSizer(input_sizer, 1, wx.EXPAND | wx.ALL, 15)
        main_sizer.AddSizer(btn_sizer, 0, wx.EXPAND | wx.ALL | wx.TOP, 15)

        self.SetSizer(main_sizer)
        self.Fit()
        self.SetSize((520, -1))

        self.folder_btn.Bind(wx.EVT_BUTTON, self.OnSelectFolder)

    def GetFolder(self):
        return self.folder_input.GetValue()

    def GetPattern(self):
        return self.pattern_input.GetValue()

    def GetDeep(self):
        return self.deep_input.GetValue()

    def IsSync(self):
        return self.sync_checkbox.GetValue()

    def OnSelectFolder(self, event):
        dir_dlg = wx.DirDialog(self)
        if dir_dlg.ShowModal() == wx.ID_OK:
            self.folder_input.SetValue(dir_dlg.GetPath())

    def Run(self):
        if self.ShowModal() == wx.ID_OK:
            self.album.sync = self.sync_checkbox.GetValue()
            self.album.folder = self.folder_input.GetValue()
            self.album.pattern = self.pattern_input.GetValue()
            self.album.deep = int(self.deep_input.GetValue())
